{extend name="default/base/base_seller" /}
{block name="seller_main"}



<div class="dssc-form-default">
    <form id="chain_form" enctype="multipart/form-data" method="post" >
        {if $Request.action=='add'}
        <dl>
            <dt><i class="required">*</i>{$Think.lang.chain_name}{$Think.lang.ds_colon}</dt>
            <dd><input type="text" value="{present name='chain_array'}{$chain_array.chain_name}{/present}" name="chain_name" id="chain_name" class="w200 text"><span></span>
                <p class="hint"></p>
            </dd>
        </dl>
        {/if}
        <dl>
            <dt>{if $Request.action=='add'}<i class="required">*</i>{/if}{$Think.lang.chain_passwd}{$Think.lang.ds_colon}</dt>
            <dd><input type="password" value="" name="chain_passwd" id="chain_passwd" class="w200 text"><span></span>
                <p class="hint">{if $Request.action=='edit'}{$Think.lang.chain_passwd_tips}{/if}</p>
            </dd>
        </dl>
        <dl>
            <dt><i class="required">*</i>{$Think.lang.chain_addressname}{$Think.lang.ds_colon}</dt>
            <dd><input type="text" value="{present name='chain_array'}{$chain_array.chain_addressname}{/present}" name="chain_addressname" id="chain_addressname" class="w200 text"><span></span>
                <p class="hint"></p></dd>
        </dl>

        <dl>
            <dt><i class="required">*</i>{$Think.lang.chain_truename}{$Think.lang.ds_colon}</dt>
            <dd><input type="text" value="{present name='chain_array'}{$chain_array.chain_truename}{/present}" name="chain_truename" id="chain_truename" class="w200 text"><span></span>
                <p class="hint"></p></dd>
        </dl>
        <dl>
            <dt><i class="required">*</i>{$Think.lang.chain_mobile}{$Think.lang.ds_colon}</dt>
            <dd><input type="text" value="{present name='chain_array'}{$chain_array.chain_mobile}{/present}" name="chain_mobile" id="chain_mobile" class="w200 text"><span></span>
                <p class="hint"></p></dd>
        </dl>
        <dl>
            <dt>{$Think.lang.chain_telephony}{$Think.lang.ds_colon}</dt>
            <dd><input type="text" value="{present name='chain_array'}{$chain_array.chain_telephony}{/present}" name="chain_telephony" id="chain_telephony" class="w200 text"><span></span>
                <p class="hint"></p></dd>
        </dl>
         <dl>
            <dt><i class="required">*</i>{$Think.lang.chain_area_info}{$Think.lang.ds_colon}</dt>
            <dd>
                <div onclick="change_map()">
                        <input type="hidden" value="{$chain_array.chain_area_2|default=''}" name="chain_area_2" id="_area_2">
                        <input type="hidden" value="{$chain_array.chain_area_3|default=''}" name="chain_area_3" id="_area">
                        <input type="hidden" name="chain_area_info" id="region" value="{$chain_array.chain_area_info|default=''}"/>
                    </div>
                <span></span>
                <p class="hint"></p></dd>
        </dl>
        <dl>
            <dt><i class="required">*</i>{$Think.lang.chain_address}{$Think.lang.ds_colon}</dt>
            <dd><input type="text" value="{present name='chain_array'}{$chain_array.chain_address}{/present}" name="chain_address" id="chain_address" class="w200 text">
                <input name="chain_longitude" id="longitude" value="{$chain_array.chain_longitude|default=''}" type="hidden" />
                <input name="chain_latitude" id="latitude" value="{$chain_array.chain_latitude|default=''}" type="hidden" />
                <div id="allmap" style="width:530px;height: 350px;margin-top: 20px"></div><span></span>
                <p class="hint"></p></dd>
        </dl>

        <dl>
            <dt><i class="required">*</i>{$Think.lang.chain_state}: </dt>
            <dd>
                <input id="chain_state1" name="chain_state" {if !isset($chain_array) || $chain_array.chain_state == '1'}checked="checked"{/if} value="1" type="radio">
                       <label for="chain_state1" class="cb-enable {if !isset($chain_array) || $chain_array.chain_state == '1'}selected{/if}" title="{$Think.lang.ds_yes}"><span>{$Think.lang.ds_yes}</span></label>
                <input id="chain_state0" name="chain_state" {if isset($chain_array) && $chain_array.chain_state == '0'}checked="checked"{/if} value="0" type="radio"></dt>
                <label for="chain_state0" class="cb-disable {if isset($chain_array) && $chain_array.chain_state == '0'}selected{/if}" title="{$Think.lang.ds_no}"><span>{$Think.lang.ds_no}</span></label>
                <p class="hint"></p></dd>
        </dl>

        <dl>
            <dt><i class="required">*</i>{$Think.lang.chain_if_pickup}: </dt>
            <dd>
                <input id="chain_if_pickup1" name="chain_if_pickup" {if !isset($chain_array) || $chain_array.chain_if_pickup == '1'}checked="checked"{/if} value="1" type="radio">
                       <label for="chain_if_pickup1" class="cb-enable {if !isset($chain_array) || $chain_array.chain_if_pickup == '1'}selected{/if}" title="{$Think.lang.ds_yes}"><span>{$Think.lang.ds_yes}</span></label>
                <input id="chain_if_pickup0" name="chain_if_pickup" {if isset($chain_array) && $chain_array.chain_if_pickup == '0'}checked="checked"{/if} value="0" type="radio"></dt>
                <label for="chain_if_pickup0" class="cb-disable {if isset($chain_array) && $chain_array.chain_if_pickup == '0'}selected{/if}" title="{$Think.lang.ds_no}"><span>{$Think.lang.ds_no}</span></label>
                <p class="hint"></p></dd>
        </dl>
        <dl>
            <dt><i class="required">*</i>{$Think.lang.chain_if_collect}: </dt>
            <dd>
                <input id="chain_if_collect1" name="chain_if_collect" {if !isset($chain_array) || $chain_array.chain_if_collect == '1'}checked="checked"{/if} value="1" type="radio">
                       <label for="chain_if_collect1" class="cb-enable {if !isset($chain_array) || $chain_array.chain_if_collect == '1'}selected{/if}" title="{$Think.lang.ds_yes}"><span>{$Think.lang.ds_yes}</span></label>
                <input id="chain_if_collect0" name="chain_if_collect" {if isset($chain_array) && $chain_array.chain_if_collect == '0'}checked="checked"{/if} value="0" type="radio"></dt>
                <label for="chain_if_collect0" class="cb-disable {if isset($chain_array) && $chain_array.chain_if_collect == '0'}selected{/if}" title="{$Think.lang.ds_no}"><span>{$Think.lang.ds_no}</span></label>
                <p class="hint"></p></dd>
        </dl>

        <div class="bottom">
            <input type="submit" class="submit" value="{$Think.lang.ds_submit}">
        </div>
    </form>
</div>
<script src="{$Think.PLUGINS_SITE_ROOT}/mlselection.js"></script>
<script type="text/javascript" src="{$Think.HTTP_TYPE}api.map.baidu.com/api?v=2.0&ak={$baidu_ak}"></script>

<script>
    var local;
    var map;
    var lst_name='';

    function change_map(){
        var name=$("#region").val();

        if(name!='' && lst_name!=name){
            lst_name=name;
            map.setCurrentCity(name);
            map.centerAndZoom(name,16);
            map.clearOverlays();
            local.search(name);
        }

    }
    //按钮先执行验证再提交表单
    $(function () {
        $("#region").ds_region();
        map = new BMap.Map("allmap");
        var lng = '{$chain_array.chain_longitude|default=""}';
        var lat = '{$chain_array.chain_latitude|default=""}';
        if(!lng && !lat){
            var geolocation = new BMap.Geolocation();
            geolocation.getCurrentPosition(function (r) {
                if (this.getStatus() == BMAP_STATUS_SUCCESS) {
                    var lng = r.point.lng;
                    var lat = r.point.lat;
                    var point = new BMap.Point(lng, lat);
                    map.centerAndZoom(point, 16);
                    map.addControl(new BMap.NavigationControl());
                    map.enableScrollWheelZoom();
                    var marker = new BMap.Marker(point);  // 创建标注
                    map.addOverlay(marker);              // 将标注添加到地图中
                    marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
                    document.getElementById("longitude").value = lng;
                    document.getElementById("latitude").value = lat;

                } else {
                    layer.msg('failed' + this.getStatus());
                }
            }, {enableHighAccuracy: true})
        }else{
            var point = new BMap.Point(lng, lat);
            map.centerAndZoom(point, 16);
            map.addControl(new BMap.NavigationControl());
            map.enableScrollWheelZoom();
            var marker = new BMap.Marker(point);  // 创建标注
            map.addOverlay(marker);              // 将标注添加到地图中
            marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
        }


        var options = {
            onSearchComplete: function(results){
                // 判断状态是否正确
                if (local.getStatus() == BMAP_STATUS_SUCCESS){
                    if(results.getCurrentNumPois()>0){

                        map.clearOverlays();  //清除标注  或者可以把market 放入数组
                        var point = new BMap.Point(results.getPoi(0).point.lng , results.getPoi(0).point.lat);
                        var marker = new BMap.Marker(point);
                        map.centerAndZoom(point, 16);
                        map.addOverlay(marker);
                        marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画

                        document.getElementById("longitude").value = results.getPoi(0).point.lng;
                        document.getElementById("latitude").value = results.getPoi(0).point.lat;

                    }
                }
            }
        };
        local = new BMap.LocalSearch(map, options);
        map.addEventListener("click", function(e){
//                    alert(e.point.lng + ", " + e.point.lat);
            map.clearOverlays();  //清除标注  或者可以把market 放入数组
            var point = new BMap.Point(e.point.lng , e.point.lat);
            var marker = new BMap.Marker(point);
            map.addOverlay(marker);
            marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画

            document.getElementById("longitude").value = e.point.lng;
            document.getElementById("latitude").value = e.point.lat;
        });
        $("#chain_form").validate({
            submitHandler: function (form) {
                ds_ajaxpost('chain_form', 'url', '{:url("seller_chain/index")}');
            },
            errorPlacement: function (error, element) {
                element.nextAll('span').first().after(error);
            },
            rules: {
                chain_name: {
                    required: true,
                    remote: {
                        url: "{:url('seller_chain/ajax',['branch'=>'chain_name'])}",
                        type: 'get',
                        data: {
                            chain_name: function () {
                                return $('#chain_name').val();
                            },
                            id: '{$chain_array.chain_id|default=0}'
                        }
                    }
                },
                chain_mobile: {
                    required: true,
                },
                chain_truename: {
                    required: true,
                },
                chain_passwd: {
                    required: {present name='chain_array'}false{else}true{/present}
                },

            },
            messages: {
                chain_name: {
                    required: '{$Think.lang.chain_name_required}',
                    remote: '{$Think.lang.chain_name_remote}'
                },
                chain_mobile: {
                    required: '{$Think.lang.chain_mobile_required}',
                },
                chain_truename: {
                    required: '{$Think.lang.chain_truename_required}',
                },
                chain_passwd: {
                    required: '{$Think.lang.chain_passwd_required}'
                },

            }
        });
    });

</script>





{/block}
